import router from './router'
import store from './store'
import Cookies from 'js-cookie'
import NProgress from 'nprogress' // Progress 进度条
import 'nprogress/nprogress.css'// Progress 进度条样式

const whiteList = ['/home','/regist','/ST/apply','/forgot','/404','/document','/scan'] // 不重定向白名单
router.beforeEach((to, from, next) => {
  NProgress.start()
  store.commit('GET_STATUS')
  store.commit('GET_TIME')
  let nowTime = new Date().getTime()
  if(store.getters.status && store.getters.time && (nowTime < store.getters.time) ) {
    next()
  } else {
    var flag = false
    for(var i in whiteList) {
      var item = whiteList[i]
      if(to.path.indexOf(item) !== -1) flag = true
    }
    if (flag) {
      next()
    } else {
      Cookies.remove('U')
      next('/home')
      NProgress.done()
    }
  }
})

router.afterEach(() => {
  NProgress.done() // 结束Progress
})
